//新增单位
function adddep(id,level){
	var url = "frontend/adddep.asp?id="+id+"&level="+level+"&timestamp="+ new Date().getTime();
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange1;
    xmlHttp.open("get",url,true);
    xmlHttp.send(null);
	document.all.topoperation.innerHTML = "新增";
}
function submitadd(id,level){
	var x = document.getElementById("addDN").value;
	var y = document.getElementById("addOC").value;
	var poststring = "x="+x+"&y="+y;
	var url = "backend/addnode.asp?id="+id+"&level="+level+"&timestamp="+ new Date().getTime();
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleAddNodeStateChange;
    xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    xmlHttp.send(poststring);
}
function handleAddNodeStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			var ajaxRequestObj = xmlHttp.responseText;
			if (ajaxRequestObj!="0"){
				refreshdep(ajaxRequestObj);
				showmsg('a','增加单位操作最后结果','新增单位成功！');
			}else{
				showmsg('a','增加单位操作最后结果','新增单位失败！单位重复！');
			}
			document.all.topoperation.innerHTML = "新增单位";
			removeshadeandoperate();
        }
    }
}

function changecurnodename(){
	//var thename = document.all.fathernodeid.options[fathernodeid.selectedIndex].text;
}
function getDepName(oriname){
	var newname = oriname.replace(/›|•/g,",").replace(/,+/g,";").split(";")[1];
	return newname.substring(1,newname.length);
}
//删除单位
function deldep(id,name){
	var delson=0;
	if (confirm("确定删除【"+name+"】？")){
		if (confirm("是否删除【"+name+"】下级单位？")){
			delson=1;
		}
		var url = "backend/delnode.asp?id="+id+"&delson="+delson+"&timestamp="+ new Date().getTime();
		createXMLHttpRequest();
		xmlHttp.onreadystatechange = handledeldepStateChange;
    	xmlHttp.open("get",url,true);
    	xmlHttp.send(null);
	}else{
		return;
	}
}

function handledeldepStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			var ajaxRequestObj = xmlHttp.responseText;
			if (ajaxRequestObj=="err"){
				showmsg('a','删除操作最后结果','删除单位失败！');
			}else{
				var rootid = ajaxRequestObj.split("|");
				refreshdep(rootid[0]);
				//refreshdepnum(rootid[0]);有问题，以后再解决
				depdetail(0,rootid[0]);
				removetag("dep"+rootid[2]);
				showmsg('a','删除操作最后结果','删除单位成功！<br><b>['+rootid[1]+']</b><br>已经删除!');
				document.all.topoperation.innerHTML = "删除单位";
			}
        }
    }
}
function refreshdepnum(id){
	var d = document.getElementById("dep"+id).getElementsByTagName("a")[1];
	var t = d.innerHTML.split("(");
	var s = t[1].split(")");
	var l = s[0]-1;
	d.innerHTML = t[0]+"("+l+")";
}
//设置本级单位
function setb(id){
	var url = "backend/setb.asp?id="+id+"&timestamp="+ new Date().getTime();
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handlesetbStateChange;
    xmlHttp.open("get",url,true);
    xmlHttp.send(null);
}

function handlesetbStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			var ajaxRequestObj = xmlHttp.responseText;
			var rootid = ajaxRequestObj.split("|");
			depdetail(1,rootid[0]);
			showmsg('a','设置操作最后结果','设置本级单位成功！<br>把<b>['+rootid[1]+']</b>设置为<br><b>['+rootid[2]+']</b>的本级单位');
			document.all.topoperation.innerHTML = "设置本级";
			refreshdep(rootid[3]);
        }
    }
}
//取消本级单位
function cancelb(id){
	var url = "backend/cancelb.asp?id="+id+"&timestamp="+ new Date().getTime();
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handlecancelbStateChange;
    xmlHttp.open("get",url,true);
    xmlHttp.send(null);
}

function handlecancelbStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			var ajaxRequestObj = xmlHttp.responseText;
			var rootid = ajaxRequestObj.split("|");
			depdetail(1,rootid[0]);
			showmsg('a','设置操作最后结果','取消本级单位成功！<br>取消<b>['+rootid[1]+']</b>所在<br><b>['+rootid[2]+']</b>的本级单位身份');
			document.all.topoperation.innerHTML = "取消本级";
			refreshdep(rootid[3]);
        }
    }
}
//取消单位统计
function unstatidep(id){
	var url = "backend/unstatinote.asp?id="+id+"&timestamp="+ new Date().getTime();
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleunstatidepStateChange;
    xmlHttp.open("get",url,true);
    xmlHttp.send(null);
}
function handleunstatidepStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			var ajaxRequestObj = xmlHttp.responseText;
			var rootid = ajaxRequestObj.split("|");
			chargenode(rootid[0]);
			showmsg('a','设置操作最后结果','取消单位统计成功！<br>取消<b>['+rootid[1]+']</b>的<br><b>['+rootid[2]+']</b>单位统计功能');
			document.all.topoperation.innerHTML = "取消统计";
        }
    }
}
//设置单位统计
function statidep(id){
	var url = "backend/statinote.asp?id="+id+"&timestamp="+ new Date().getTime();
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handlestatidepStateChange;
    xmlHttp.open("get",url,true);
    xmlHttp.send(null);
}
function handlestatidepStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			var ajaxRequestObj = xmlHttp.responseText;
			var rootid = ajaxRequestObj.split("|");
			chargenode(rootid[0]);
			showmsg('a','设置操作最后结果','设置单位统计成功！<br>设置<b>['+rootid[1]+']</b>的<br><b>['+rootid[2]+']</b>单位统计功能');
			document.all.topoperation.innerHTML = "设置统计";
        }
    }
}
//取消部委统计
function unstatiroot(id){
	var url = "backend/unstatiroot.asp?id="+id+"&timestamp="+ new Date().getTime();
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleunstatirootStateChange;
    xmlHttp.open("get",url,true);
    xmlHttp.send(null);
}
function handleunstatirootStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			var ajaxRequestObj = xmlHttp.responseText;
			var rootid = ajaxRequestObj.split("|");
			chargenode(rootid[0]);
			showmsg('a','设置操作最后结果','取消部委统计成功！<br>取消<b>['+rootid[1]+']</b>的<br><b>['+rootid[2]+']</b>部委统计功能');
			document.all.topoperation.innerHTML = "取消统计";
        }
    }
}
//设置部委统计
function statiroot(id){
	var url = "backend/statiroot.asp?id="+id+"&timestamp="+ new Date().getTime();
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handlestatirootStateChange;
    xmlHttp.open("get",url,true);
    xmlHttp.send(null);
}
function handlestatirootStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			var ajaxRequestObj = xmlHttp.responseText;
			var rootid = ajaxRequestObj.split("|");
			chargenode(rootid[0]);
			showmsg('a','设置操作最后结果','设置部委统计成功！<br>设置<b>['+rootid[1]+']</b>的<br><b>['+rootid[2]+']</b>部委统计功能');
			document.all.topoperation.innerHTML = "设置统计";
        }
    }
}

//统计节点
function statinode(id,x){
	var url = "frontend/statidep.asp?id="+id+"&x="+x+"&timestamp="+ new Date().getTime();
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = getstatiStateChange;
    xmlHttp.open("get",url,true);
    xmlHttp.send(null);
	document.all.topoperation.innerHTML = "统计";
}

function getstatiStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
		var ajaxRequestObj = xmlHttp.responseText;
		shadeandoperate(1);
		document.getElementById(nowdiv+"_operate").innerHTML = ajaxRequestObj;
		var t = document.getElementById(nowdiv).getElementsByTagName("table");
		if(t[2]!=null){
			t[2].style.height=document.getElementById(nowdiv).clientHeight-69;
		}else{
			t[1].style.height=document.getElementById(nowdiv).clientHeight-69;
		}
		setTimeout("clearloading()",500);
        }
    }
}
//统计计划
function statiplan(id,x){
	var url = "frontend/statiplan.asp?id="+id+"&x="+x+"&timestamp="+ new Date().getTime();
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = getstatiStateChange;
    xmlHttp.open("get",url,true);
    xmlHttp.send(null);
	document.all.topoperation.innerHTML = "统计";
}
//查看项目
function project(id,x){
	var url = "frontend/project.asp?id="+id+"&x="+x+"&timestamp="+ new Date().getTime();
	//alert(url);
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = getstatiStateChange;
    xmlHttp.open("get",url,true);
    xmlHttp.send(null);
	document.all.topoperation.innerHTML = "项目";
}
//提交计划
function applyplan(){
	document.all.applyplanform.submit(); 
 	document.all.topoperation.innerHTML = "提交计划";
}
function clearloading(){
	var s = document.getElementById(nowdiv).getElementsByTagName("iframe")[0];
	if(s!=null){
		if(s.contentWindow.document.all.myform!=null || s.contentWindow.document.all.TongJiForm!=null){
			delloadingpic();
		}else{
			setTimeout("clearloading()",100);
		}
	}else{
		setTimeout("clearloading()",100);
	}
}

function dofix(){
	alert(1);
}


//锁定单位
function lockdep(id,v){
	var url;
	if (v==1){
		if (confirm("是否锁定下级单位？")){
			url = "backend/lockdep.asp?id="+id+"&v="+v+"&all=y&timestamp="+ new Date().getTime();
		}else{
			url = "backend/lockdep.asp?id="+id+"&v="+v+"&timestamp="+ new Date().getTime();
		}
	}else{
		if (confirm("是否解锁下级单位？")){
			url = "backend/lockdep.asp?id="+id+"&v="+v+"&all=y&timestamp="+ new Date().getTime();
		}else{
			url = "backend/lockdep.asp?id="+id+"&v="+v+"&timestamp="+ new Date().getTime();
		}
	}
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handlelockdepStateChange;
	xmlHttp.open("get",url,true);
	xmlHttp.send(null);
}

function handlelockdepStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			var ajaxRequestObj = xmlHttp.responseText;
			var rootid = ajaxRequestObj.split("|");
			depdetail(1,rootid[1]);
			if (rootid[2]==1){
				showmsg('a','锁定操作最后结果','锁定单位成功！<br><b>['+rootid[0]+']</b><br>已经锁定!');
			}else{
				showmsg('a','锁定操作最后结果','解锁单位成功！<br><b>['+rootid[0]+']</b><br>已经解锁!');
			}
        }
    }
}

//禁止单位注册
function allowreg(id,v){
	var url;
	var vt = 3;
	if (v!=3){
		if (confirm("不允许本单位下注册用户？")){
			vt -= 1;
		}
		if (confirm("不允许注册下级单位？")){
			vt -= 2;
		}
	}
	if (confirm("是否应用相同设置到下级单位？")){
		url = "backend/allowreg.asp?id="+id+"&v="+vt+"&all=y&timestamp="+ new Date().getTime();
	}else{
		url = "backend/allowreg.asp?id="+id+"&v="+vt+"&timestamp="+ new Date().getTime();
	}
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleallowregStateChange;
	xmlHttp.open("get",url,true);
	xmlHttp.send(null);
}

function handleallowregStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			var ajaxRequestObj = xmlHttp.responseText;
			var rootid = ajaxRequestObj.split("|");
			depdetail(rootid[1]<200?0:1,rootid[1]);
			if (rootid[2]==3||(rootid[1]<200&&rootid[2]==1)){
				showmsg('a','设置注册最后结果','允许注册成功！<br><b>['+rootid[0]+']</b><br>允许注册用户!');
			}else{
				showmsg('a','设置注册最后结果','禁止注册成功！<br><b>['+rootid[0]+']</b><br>禁止注册用户!');
			}
        }
    }
}

//禁止部委注册
function allowrootreg(id,v){
	var url = "backend/allowrootreg.asp?id="+id+"&v="+v+"&timestamp="+ new Date().getTime();
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleallowregStateChange;
	xmlHttp.open("get",url,true);
	xmlHttp.send(null);
}